package code.rocky.consumer;

public class InterruptTest1 {

    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();
        new Thread(() -> {
            System.out.println("====start======");
//            try {
//                Thread.sleep(3000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            mainThread.interrupt();
            boolean interrupted = Thread.interrupted(); //currentThread().isInterrupted(true); 清除标志位
            boolean interrupted1 = Thread.interrupted(); //currentThread().isInterrupted(true); 清除标志位
            System.out.println(" Thread.interrupted(): " + interrupted);
            System.out.println(" Thread.interrupted(): " + interrupted1);

            boolean isInterrupted = Thread.currentThread().isInterrupted(); // 不清除中断标记
            boolean isInterrupted1 = Thread.currentThread().isInterrupted(); // 不清除中断标记

            System.out.println("Thread.currentThread().isInterrupted() " + isInterrupted);
            System.out.println("Thread.currentThread().isInterrupted() " + isInterrupted1);

            System.out.println("====end========");
        }).start();

        // interrupt 字面意思是中断,实际上不能中断
        while (true) {
            // 这样子包一层能中断 加一层try catch 中断不了 手动休眠也中断不了
            Thread.sleep(1000);
            System.out.println(mainThread.getName() + " ======");
        }
    }
}
